package com.admin.servlet;

import com.admin.service.IAdminService;
import com.admin.service.impl.AdminServiceImpl;
import com.user.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DeleteUserServlet", value = "/DeleteUserServlet")
public class DeleteUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        IAdminService adminService = new AdminServiceImpl();
        boolean result = adminService.deleteUsers(new Users(id));
        if (result) {
            request.setAttribute("msg", "删除成功！");
            request.getRequestDispatcher("/UserListServlet").forward(request, response);

        } else {
            request.setAttribute("msg", "删除失败！");
            request.getRequestDispatcher("/UserListServlet").forward(request, response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
